package com.example.myapplication9.weeek3;

import java.util.LinkedList;
import java.util.Queue;

/**
 * TicketCounter demonstrates the use of Translation queue for simulating Translation line of customers.
 *
 * @author Lewis and Chase
 * @version 4.0
 */
public class TicketCounter    
{
    private final static int PROCESS = 120;
    private final static int MAX_CASHIERS = 10;
    private final static int NUM_CUSTOMERS = 100;

    public static void main(String[] args) 
    {
        Customer customer;
        Queue<Customer> customerQueue = new LinkedList<Customer>();
        int[] cashierTime = new int[MAX_CASHIERS];	
        int totalTime, averageTime, departs, start;

        // 为不同数量的收银员运行模拟
        for (int cashiers = 0; cashiers < MAX_CASHIERS; cashiers++)
        { 
            // 将每个收银员的时间设置为零
            for (int count = 0; count < cashiers; count++)
                cashierTime[count] = 0;

            // 加载客户队列
            for (int count = 1; count <= NUM_CUSTOMERS; count++)
                customerQueue.add(new Customer(count * 15));

            totalTime = 0;

            // 处理队列中的所有客户
            while (!(customerQueue.isEmpty())) 
            {
                for (int count = 0; count <= cashiers; count++)
                {
                    if (!(customerQueue.isEmpty()))
                    {
                        customer = customerQueue.remove();
                        if (customer.getArrivalTime() > cashierTime[count])
						    start = customer.getArrivalTime();
                        else
                            start = cashierTime[count]; 
						departs = start + PROCESS;
					    customer.setDepartureTime(departs);
                        cashierTime[count] = departs;
                        totalTime += customer.totalTime();
                    }
                }
            }

            // 这个模拟的输出结果
            averageTime = totalTime / NUM_CUSTOMERS;
            System.out.println("Number of cashiers: " + (cashiers + 1));
            System.out.println("Average time: " + averageTime + "\n");
        }
    }
}
